import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:permission_handler/permission_handler.dart';

import 'Config.dart';


class LoadingDialog {
  static void show(BuildContext context) {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return  LoadingAnimationWidget.hexagonDots(color: Colors.white, size: 60);
      },
    );
  }

  static void hide(BuildContext context) {
    Navigator.of(context).pop();
  }
}
void showPhotosFirstDialog(BuildContext context) {
  final screenSize = MediaQuery.of(context).size;

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return GestureDetector(
        child: Align(
        alignment: Alignment.topCenter,
        child: Container(
            height: 100.h,
            color: Colors.white,
            width: screenSize.width,
            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 15.h,bottom: 10.h),
            child: Column(
              children: [
                Text("速配货想要获取您的相册权限，用于获取或上传相册内的图片,若要使用相册功能，需要您的允许",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                TextButton(onPressed: (){
                    Navigator.pop(context);
                  }, child: Text("我知道了",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),)),
              ],
            ),
          ),

        ),
        onTap: (){
          Navigator.pop(context);
        },
      );
    },
  );
}

void showPhotosDialog(BuildContext context) {

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return Align(
        alignment: Alignment.center,
        child: BrnDialog(
          titleText: "您未开启相册权限",
          messageText: "速配货想要获取您的相册权限，用于获取或上传相册内的图片。",
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text(
                "取消",
                style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
              ),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context);
                openAppSettings();
              },
              child: Text(
                "去开启",
                style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),
              ),
            ),
          ],
        ),
      );
    },
  );
}
void showCameraFirstDialog(BuildContext context) {
  final screenSize = MediaQuery.of(context).size;

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return GestureDetector(
        child: Align(
          alignment: Alignment.topCenter,
          child: Container(
            height: 100.h,
            color: Colors.white,
            width: screenSize.width,
            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 15.h,bottom: 10.h),
            child: Column(
              children: [
                Text("速配货想要获取您的相机权限，用于拍照或上传图片,若要使用相机功能，需要您的允许",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                TextButton(onPressed: (){
                  Navigator.pop(context);
                }, child: Text("我知道了",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),)),
              ],
            ),
          ),

        ),
        onTap: (){
          Navigator.pop(context);
        },
      );
    },
  );
}

void showCameraDialog(BuildContext context) {

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return Align(
        alignment: Alignment.center,
        child: BrnDialog(
          titleText: "您未开启相机权限",
          messageText: "速配货想要获取您的相机权限，用于拍照上传图片。",
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text(
                "取消",
                style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
              ),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context);
                openAppSettings();
              },
              child: Text(
                "去开启",
                style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),
              ),
            ),
          ],
        ),
      );
    },
  );
}
void showLocFirstDialog(BuildContext context) {
  final screenSize = MediaQuery.of(context).size;

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return GestureDetector(
        child: Align(
          alignment: Alignment.topCenter,
          child: Container(
            height: 100.h,
            color: Colors.white,
            width: screenSize.width,
            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 15.h,bottom: 10.h),
            child: Column(
              children: [
                Text("速配货想要获取您的位置信息，确保定位、地图等相关功能的正常使用,若要使用定位功能，需要您的允许",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                TextButton(onPressed: (){
                  Navigator.pop(context);
                }, child: Text("我知道了",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),)),
              ],
            ),
          ),

        ),
        onTap: (){
          Navigator.pop(context);
        },
      );
    },
  );
}

void showLocDialog(BuildContext context) {

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return Align(
        alignment: Alignment.center,
        child: BrnDialog(
          titleText: "您未开启相机权限",
          messageText: "速配货想要获取您的位置权限，用于定位、地图、找货等功能。",
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text(
                "取消",
                style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
              ),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context);
                openAppSettings();
              },
              child: Text(
                "去开启",
                style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),
              ),
            ),
          ],
        ),
      );
    },
  );
}
void showMicrophoneFirstDialog(BuildContext context) {
  final screenSize = MediaQuery.of(context).size;

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return GestureDetector(
        child: Align(
          alignment: Alignment.topCenter,
          child: Container(
            height: 100.h,
            color: Colors.white,
            width: screenSize.width,
            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 15.h,bottom: 10.h),
            child: Column(
              children: [
                Text("速配货想要获取您的麦克风权限，用于语音识别等功能，方便更快捷的找货",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                TextButton(onPressed: (){
                  Navigator.pop(context);
                }, child: Text("我知道了",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),)),
              ],
            ),
          ),

        ),
        onTap: (){
          Navigator.pop(context);
        },
      );
    },
  );
}

void showMicrophoneDialog(BuildContext context) {

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return Align(
        alignment: Alignment.center,
        child: BrnDialog(
          titleText: "您未开启麦克风权限",
          messageText: "速配货想要获取您的麦克风权限，用于语音识别等功能。",
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text(
                "取消",
                style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
              ),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context);
                openAppSettings();
              },
              child: Text(
                "去开启",
                style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),
              ),
            ),
          ],
        ),
      );
    },
  );
}
void showCallPhoneFirstDialog(BuildContext context) {
  final screenSize = MediaQuery.of(context).size;

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return GestureDetector(
        child: Align(
          alignment: Alignment.topCenter,
          child: Container(
            height: 100.h,
            color: Colors.white,
            width: screenSize.width,
            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 15.h,bottom: 10.h),
            child: Column(
              children: [
                Text("速配货想要获取您的电话权限，用于联系货主功能，方便更快捷的找货",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                TextButton(onPressed: (){
                  Navigator.pop(context);
                }, child: Text("我知道了",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),)),
              ],
            ),
          ),

        ),
        onTap: (){
          Navigator.pop(context);
        },
      );
    },
  );
}

void showCallPhoneDialog(BuildContext context) {

  showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return Align(
        alignment: Alignment.center,
        child: BrnDialog(
          titleText: "您未开启电话权限",
          messageText: "速配货想要获取您的电话权限，用于拨打电话联系货主。",
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text(
                "取消",
                style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
              ),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context);
                openAppSettings();
              },
              child: Text(
                "去开启",
                style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),
              ),
            ),
          ],
        ),
      );
    },
  );
}